<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('养修服务项列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            名称：<input type="text" name="name"/>
                        </li>
                        <li>
                            是否套餐：
                            <select name="carPackage" th:with="type=${@dict.getType('si_car_package')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            服务分类：
                            <select name="serviceCatalog" th:with="type=${@dict.getType('si_service_catalog')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            审核状态：
                            <select name="auditStatus" th:with="type=${@dict.getType('si_audit_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            上架状态：
                            <select name="saleStatus" th:with="type=${@dict.getType('si_sale_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:serviceItem:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-warning auditBtn" onclick="startAudit()" >
                <i class="fa fa-download"></i> 发起审核
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<script th:inline="javascript">

    var carPackage = [[${@dict.getType('si_car_package')}]];
    var serviceCatalog = [[${@dict.getType('si_service_catalog')}]];
    var auditStatus = [[${@dict.getType('si_audit_status')}]];
    var saleStatus = [[${@dict.getType('si_sale_status')}]];
    var prefix = ctx + "/business/serviceItem";

    var deitFlag = [[${@permission.hasPermi('business:serviceItem:edit')}]];
    var saleOnFlag = [[${@permission.hasPermi('business:serviceItem:saleOn')}]];
    var saleOffFlag = [[${@permission.hasPermi('business:serviceItem:saleOff')}]];

    $(function () {
        // options 定义分页 新增url，删除url，属性
        // options 简单的理解就是我们界面中可能要用到的一些属性
        var options = {
            url: prefix + "/query",						// 查询url
            createUrl: prefix + "/addPage",				// 跳转到新增界面url
            updateUrl: prefix + "/editPage?id={id}",	// 跳转到编辑界面url
            removeUrl: prefix + "/remove",				// 删除url
            modalName: "养修服务项",							// 模态框名称
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',							// 字段名字
                    title: '服务项id',						// 标题头名字
                    visible: false							// 是否隐藏 设置成false隐藏窗台
                },
                {
                    field: 'name',
                    title: '服务项名称',
                    sortable: true
                },

                {
                    field: 'originalPrice',
                    title: '服务项原价',
                    sortable: true
                },
                {
                    field: 'discountPrice',
                    title: '服务项折扣价',
                    sortable: true
                },
                {
                    field: 'carPackage',
                    title: '是否套餐',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (row.carPackage) {
                            return '是';
                        } else {
                            return '否';
                        }
                    }
                },
                {
                    field: 'info',
                    title: '备注信息',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 6, "open");
                    }
                },

                {
                    field: 'serviceCatalog',
                    title: '服务分类',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(serviceCatalog, value);
                    }
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(auditStatus, value);
                    }
                },
                {
                    field: 'saleStatus',
                    title: '上架状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(saleStatus, value);
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        var editStyle = '';
                        // 如果是是上架状态且是审核中编辑按钮变灰
                        if (row.saleStatus == 1 || row.auditStatus == 1) {
                            editStyle = 'disabled';
                        }
                        actions.push('<a class="btn btn-success btn-xs  ' + editStyle + ' "href="javascript:void(0)" ' +
                            'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        if (row.saleStatus == 0) {
                            var saleStyle = '';
                            // 判断如果是套餐 但审核状态是非审核通过 按钮变灰
                            if (row.auditStatus != 2 && row.carPackage) {
                                saleStyle = 'disabled';
                            }

                            actions.push('<a class="btn btn-warning btn-xs ' + saleStyle + '" href="javascript:void(0)"' +
                                ' onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>上架</a>');
                        } else {
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)"' +
                                ' onclick="saleOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>下架</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function saleOff(id) {
        // 下架
      $.modal.confirm("确定下架此服务项吗?",function () {
        // 发送ajax请求
          $.operate.get(prefix + "/saleOff?id="+id);
      })
    }
    function saleOn(id) {
        // 上架
        $.modal.confirm("确定上架此服务项吗?",function () {
           // 发送ajax请求
            $.operate.get(prefix + "/saleOn?id="+ id);
        })
    }

    //发起审核
    function startAudit(){
        var rows = $.table.selectColumns("id");
        //选中id列 第0个值
        var url =  prefix + "/auditPage?id="+ rows[0];
        $.modal.open("发起审核",url);
    }
</script>
</body>
</html>